package com.example.demo.gateway.filter.factory;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Auther: miaoguoxin
 * @Date: 2020/4/14 20:15
 * @Description:
 */
@Component
public class DispatchGatewayFilterFactory extends AbstractGatewayFilterFactory<DispatchGatewayFilterFactory.Config> implements Ordered {

    public DispatchGatewayFilterFactory() {
        super(Config.class);
    }
    @Override
    public GatewayFilter apply(Config config) {
        return new DispatchGatewayFilter();
    }

    static class DispatchGatewayFilter implements GatewayFilter,Ordered{

        @Override
        public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
            return chain.filter(exchange);
        }

        @Override
        public int getOrder() {
            return 10;
        }
    }

    @Override
    public int getOrder() {
        return 10;
    }

    @Data
    public static class Config {
        //限流策略key的bean名称
        private String keyResolverName;
    }
}
